<template>
  <div class="page-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="15">
        <!--        <el-form inline :model="queryForm" @submit.prevent>-->
        <!--          <el-form-item label="关键词">-->
        <!--            <el-input-->
        <!--              v-model.trim="queryForm.platformAccount"-->
        <!--              clearable-->
        <!--              placeholder="请输入关键词"-->
        <!--            />-->
        <!--          </el-form-item>-->
        <!--          <el-form-item>-->
        <!--            <el-button :icon="Search" type="primary" @click="queryData">-->
        <!--              查询-->
        <!--            </el-button>-->
        <!--          </el-form-item>-->
        <!--        </el-form>-->
      </vab-query-form-left-panel>
    </vab-query-form>

    <el-table v-loading="listLoading" border :data="list">
      <el-table-column
        type="index"
        width="60"
        header-align="center"
        align="center"
        label="序号"
      />
      <el-table-column
        label="平台账号"
        prop="platformAccount"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <!--      <el-table-column-->
      <!--        label="所属平台"-->
      <!--        prop="platformName"-->
      <!--        show-overflow-tooltip-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--      />-->
      <el-table-column
        label="累计/新增访问数"
        prop="newVisitsNumber"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="观看时长"
        prop="watchTime"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="新增点赞"
        prop="newPraise"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="新增评论"
        prop="newReview"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="新增笔记分享"
        prop="newNote"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="笔记涨粉"
        prop="chalkUp"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="薯条消耗"
        prop="frenchFryConsumption"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="主页访问"
        prop="homeVisitNum"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="私信量"
        prop="communicationNum"
        show-overflow-tooltip
        header-align="center"
      />
      <el-table-column
        label="有效客资"
        prop="canGuestCapital"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="新客成单数"
        prop="newSuccessfulNum"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="新客成交额"
        prop="newSuccessfulPrice"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="老客成单数"
        prop="oldSuccessfulNum"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="老客成交额"
        prop="oldSuccessfulPrice"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="总成交单数"
        prop="successfulSum"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="成交总额"
        prop="successfulSumPrice"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="有效客资数"
        prop="canGuestCapitalRate"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="客资成本"
        prop="costGuestCapital"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="成交率"
        prop="transactionRate"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="ROI"
        prop="hroi"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />
      <el-table-column
        label="创建时间"
        prop="createTime"
        show-overflow-tooltip
        header-align="center"
        align="center"
      />

      <template #empty>
        <el-empty class="vab-data-empty" description="暂无数据" />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <edit ref="editRef" :platform-id="platformId" @fetch-data="fetchData" />
  </div>
</template>

<script>
  import { Delete, Plus, Search } from '@element-plus/icons-vue'
  import {
    // deleteTopicRecord,
    // fetchTopicRecord,
    fetchTopicRecordList,
    // flexibleTopicRecord,
    // editTopicRecord,
  } from '@/api/topics'
  export default defineComponent({
    name: 'MyAssetList',
    components: {
      Edit: defineAsyncComponent(() => import('./components/Edit')),
    },
    setup() {
      // const $baseConfirm = inject('$baseConfirm')
      // const $baseMessage = inject('$baseMessage')
      // const router = useRouter()
      const state = reactive({
        editRef: null,
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          name: '',
          status: '',
          pageNum: 1,
          pageSize: 10,
        },
        statusList: [
          {
            label: '闲置中',
            value: 0,
          },
          {
            label: '使用中',
            value: 1,
          },
          {
            label: '报废',
            value: 2,
          },
        ],
        platformId: null,
      })
      const route = useRoute()
      // const id = route.query.id

      const setSelectRows = (val) => {
        state.selectRows = val
      }

      const handleSizeChange = (val) => {
        state.queryForm.pageSize = val
        fetchData()
      }
      const handleCurrentChange = (val) => {
        state.queryForm.pageNum = val
        fetchData()
      }
      const queryData = () => {
        state.queryForm.pageNum = 1
        fetchData()
      }
      const fetchData = async () => {
        try {
          state.listLoading = true
          // state.queryForm.platformId = id
          const { data } = await fetchTopicRecordList(state.queryForm)
          state.list = data.list
          state.total = data.total
          state.listLoading = false
        } catch (e) {
          console.log(e)
        }
      }
      onMounted(() => {
        fetchData()
        state.platformId = route.query.platformId
      })

      return {
        ...toRefs(state),
        setSelectRows,
        handleSizeChange,
        handleCurrentChange,
        queryData,
        fetchData,
        // handleDetail,
        Delete,
        Plus,
        Search,
      }
    },
  })
</script>

<style scoped>
  .toolbar {
    margin-bottom: 4px;
  }
</style>
